package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tiantianyuegou.R;
import com.tiantianyuegou.model.TuanGouInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/1/13.
 */
public class TuangouHottingAdapter extends BaseAdapter{
    Context mContext;
    List<TuanGouInfo> tuanGouInfoList;
    private LayoutInflater inflater;

    public TuangouHottingAdapter(Context mContext, List<TuanGouInfo> tuanGouInfoList) {
        this.mContext = mContext;
        this.tuanGouInfoList = tuanGouInfoList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return tuanGouInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if(view == null){
            view = inflater.inflate(R.layout.list_item_tuangouhoting,null);
            holder = new ViewHolder();
            holder.store = (ImageView) view.findViewById(R.id.iv_store);
            holder.tuangou_hottitle = (TextView) view.findViewById(R.id.tv_tuangou_hottitle);
            view.setTag(holder);


        }else{
            holder = (ViewHolder) view.getTag();
        }
        ImageLoader.getInstance().init(
                ImageLoaderConfiguration.createDefault(mContext));
        ImageLoader.getInstance().displayImage(
                tuanGouInfoList.get(position).getTtPic(),
                holder.store);
        holder.tuangou_hottitle.setText(tuanGouInfoList.get(position).getTtTitle());

        return view;
    }
    class ViewHolder{
        ImageView store;
        TextView tuangou_hottitle;
    }
}
